package com.fount4j.generator.context;

import com.fount4j.generator.config.TableConfig;
import com.fount4j.generator.info.FileInfo;
import com.fount4j.generator.info.TableInfo;
import com.fount4j.generator.introspector.extend.ColumnIntrospector;
import com.fount4j.generator.introspector.extend.TableIntrospector;
import com.fount4j.generator.introspector.DataSourceIntrospector;
import com.fount4j.generator.introspector.FileIntrospector;
import org.beetl.core.Template;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 生成器上下文
 *
 * @author Morven 2016/12/22
 */
public class GeneratorContext {
    /** 数据源解析 */
    protected DataSourceIntrospector dataSourceIntrospector;
    /** 解析器 */
    protected TableIntrospector tableIntrospector;
    /** 要生成的数据库表名 */
    protected List<TableConfig> tables;
    /** 其他配置项 */
    protected Map<String, Object> properties;
    /** 表配置信息 */
    protected TableConfig tableConfig;
    /** 表结构信息 */
    protected TableInfo tableInfo;
    /** 列解析器 */
    protected ColumnIntrospector columnIntrospector;
    /** ClassLoader */
    protected ClassLoader classLoader;
    /** 解析出的 info 对象 */
    protected Map<String, FileInfo> infoMap = new HashMap<>();
    /** 解析器 */
    protected List<FileIntrospector> introspectors = new ArrayList<>();
    /** 模板 map */
    protected Map<String, Template> templateMap = new HashMap<>();

    public TableIntrospector getTableIntrospector() {
        return tableIntrospector;
    }

    public void setTableIntrospector(TableIntrospector tableIntrospector) {
        this.tableIntrospector = tableIntrospector;
    }

    public List<TableConfig> getTables() {
        return tables;
    }

    public void setTables(List<TableConfig> tables) {
        this.tables = tables;
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }

    public TableInfo getTableInfo() {
        return tableInfo;
    }

    public void setTableInfo(TableInfo tableInfo) {
        this.tableInfo = tableInfo;
    }

    public ColumnIntrospector getColumnIntrospector() {
        return columnIntrospector;
    }

    public void setColumnIntrospector(ColumnIntrospector columnIntrospector) {
        this.columnIntrospector = columnIntrospector;
    }

    public TableConfig getTableConfig() {
        return tableConfig;
    }

    public void setTableConfig(TableConfig tableConfig) {
        this.tableConfig = tableConfig;
    }

    public ClassLoader getClassLoader() {
        return classLoader;
    }

    public void setClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    public DataSourceIntrospector getDataSourceIntrospector() {
        return dataSourceIntrospector;
    }

    public void setDataSourceIntrospector(DataSourceIntrospector dataSourceIntrospector) {
        this.dataSourceIntrospector = dataSourceIntrospector;
    }

    public Map<String, FileInfo> getInfoMap() {
        return infoMap;
    }

    public void setInfoMap(Map<String, FileInfo> infoMap) {
        this.infoMap = infoMap;
    }

    public <T extends FileInfo> T getInfo(String key) {
        FileInfo fileInfo = infoMap.get(key);
        return (T) fileInfo;
    }

    public List<FileIntrospector> getIntrospectors() {
        return introspectors;
    }

    public void setIntrospectors(List<FileIntrospector> introspectors) {
        this.introspectors = introspectors;
    }

    public void putInfo(String infoKey, FileInfo info) {
        infoMap.put(infoKey, info);
    }

    public Map<String, Template> getTemplateMap() {
        return templateMap;
    }

    public void setTemplateMap(Map<String, Template> templateMap) {
        this.templateMap = templateMap;
    }

    public void putTemplate(String key, Template template) {
        this.templateMap.put(key, template);
    }

    public Template getTemplate(String key) {
        return this.templateMap.get(key);
    }
}
